<% layout('/layouts/default.html', {title: '车辆物流状态查询更新', libs: ['dataGrid']}){ %>
<div class="main-content">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-notebook"></i> ${text('车辆物流状态查询更新')}
            </div>
        </div>
        <div class="box-body">
            <#form:form id="searchForm" model="${serviceOrder}" action="${ctx}/logistics/vehicleLogisticsStatusQuery/updateNumberListData" method="post" class="form-inline"
            data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
            <div class="form-group">
                <label class="control-label">${text('服务订单编号')}：</label>
                <div class="control-inline">
                    <#form:input path="serviceOrderId" maxlength="100" class="form-control width-120"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label">${text('订单状态')}：</label>
                <div class="control-inline width-120">
                    <#form:select path="orderStatus" dictType="order_status" blankOption="true" class="form-control"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label">${text('客户')}：</label>
                <div class="control-inline width-120">
                    <#form:treeselect id="customer" title="${text('客户选择')}"
                    path="customer.customerId" labelPath="customer.customerName"
                    url="${ctx}/base/customer/customer/treeData" canSelectRoot="true" canSelectParent="true"
                    class=" required" allowClear="true"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label">${text('车辆名称')}：</label>
                <div class="control-inline width-120">
                    <#form:input path="carName" maxlength="100" class="form-control width-120"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label">${text('车架号')}：</label>
                <div class="control-inline width-120">
                    <#form:input path="frameNumber" maxlength="100" class="form-control width-120"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label">${text('创建时间')}：</label>
                <div class="control-inline">
                    <#form:input path="createDateGte" readonly="true" maxlength="20" class="form-control laydate width-datetime"
                    dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm" data-done="createDate_lte.click()"/>
                    &nbsp;-&nbsp;
                    <#form:input path="createDateLte" readonly="true" maxlength="20" class="form-control laydate width-datetime"
                    dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm"/>
                </div>
            </div>
            <div class="form-group">
                <button type="submit" id="searchButton" class="btn btn-primary btn-sm">${text('查询')}</button>
                <button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
            </div>
            <div class="form-unit">${text('车辆信息')} &nbsp;&nbsp;&nbsp;&nbsp;<button type="button" id="updateFrameNumber" class="btn btn-primary btn-sm">${text('更新  ')}</button></div>
        </#form:form>
        <table id="dataGrid"></table>
        <div id="dataGridPage"></div>
    </div>
</div>
</div>
<% } %>
<script>
    // 初始化DataGrid对象
    $('#dataGrid').dataGrid({

        searchForm: $("#searchForm"),
        columnModel: [
            {header:'${text("服务订单名称")}', name:'serviceOrderCode', index:'', width:150, align:"center"},
            {header:'${text("车架号")}', name:'frameNumber', index:'', width:150, align:"center"},
            {header:'${text("车辆名称")}', name:'carName', index:'', width:150, align:"center"},
            {header:'${text("车辆所在仓库")}', name:'warehouseName', index:'', width:150, align:"center"},
            {header:'${text("车辆当前状态")}', name:'logisticsStatus', index:'a.logisticsStatus', width:150, align:"center", formatter: function(val, obj, row, act){
                return js.getDictLabel(${@DictUtils.getDictListJson('erp_logistics_status')}, val, '${text("")}', true);
            }},
            {header:'${text("更新状态")}', name:'Status',index:'', edittype:'select',editable:true, editoptions:{'class':'form-control',
                items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('erp_logistics_status')}),
                itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
                    $(element).select2().on("change",function(){});
                }
            }}
        ],
        showCheckbox: true,  // 是否显示复选框
        editGrid: true,		// 是否是编辑表格
        multiSort: false,  // 是否支持多列排序
        editGridInitRowNum: 0,
        editGridInputFormListName: 'dataGrid', // 提交的数据列表名
        editGridInputFormListAttrs: 'frameNumber,serviceOrderCode,Status',
        // 加载成功后执行事件
        ajaxSuccess: function(data){

        }
    });


    $('#updateFrameNumber').click(function () {
        var ids = $('#dataGrid').dataGrid('getSelectRows');
        var frameNumberArr = [];
        for (var i = 0; i < ids.length ; i++) {
            $('#dataGrid').dataGrid('saveRow', ids[i], true);
            $("#dataGrid").dataGrid("restoreRow", ids[i]);
            // var status =$("tr[id="+ids[i]+"]").find("select[name=\"Status\"]").find("option");
            var lineData = $('#dataGrid').dataGrid('getRowData', ids[i]);

            frameNumberArr.push({
                "serviceOrderCode":lineData.serviceOrderCode,
                "frameNumber":lineData.frameNumber,
                "Status":lineData.Status
            });
            $("#dataGrid").dataGrid("editRow", ids[i], {keys: true, focusField: true});
        }

        if (frameNumberArr.length<=0){
            js.alert("请勾选要修改的车辆信息！");
        }else {
            $.ajax({
                type: "POST",
                async : false,
                url : "${ctx}/logistics/vehicleLogisticsStatusQuery/updateStatus",
                data: {"NumberArr": JSON.stringify(frameNumberArr)},
                dataType:"json",
                success: function (result) {
                    js.showMessage(result.message);
                    if (result.result == 'true'){
                        $('#dataGrid').dataGrid('reloadGrid');
                    }
                }
            });
        }
    });

</script>